﻿@Html.DevExpress().GridView(
    settings => {
        settings.Name = "gvEditing";
        settings.KeyFieldName = "FItemPurchaseApplyID";
        settings.CallbackRouteValues = new { Controller = "OfficeItemPurchaseApply", Action = "OfficeItemPurchaseApplyListPartial" };
        settings.Width = System.Web.UI.WebControls.Unit.Percentage(96);
        
        settings.Columns.Add(column =>
        {
            column.Caption = "操作";

            column.SetDataItemTemplateContent(c =>
            {
                Html.DevExpress().HyperLink(s => 
                { 
                    s.Name = "linkEdit" + c.VisibleIndex; 
                    s.ToolTip = "修改"; 
                    s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_Edit.png");
                    s.Properties.ClientSideEvents.Click = "function(){itemApplyEdit('" + DataBinder.Eval(c.DataItem, "FItemPurchaseApplyID") + "')}";
                    s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer"); 
                }).GetHtml();
                ViewContext.Writer.Write("  ");
                Html.DevExpress().HyperLink(s => { 
                    s.Name = "linkDel" + c.VisibleIndex; 
                    s.ToolTip = "删除";
                    s.Properties.ImageUrl = Url.Content("~/Content/ControlImages/button_delete.png");
                    s.Properties.ClientSideEvents.Click = "function(){itemApplyDel('" + DataBinder.Eval(c.DataItem, "FItemPurchaseApplyID") + "')}";
                    s.Style.Add(HtmlTextWriterStyle.Cursor, "pointer"); 
                }).GetHtml();

            });
            column.Settings.AllowDragDrop = DefaultBoolean.False;
            column.Settings.AllowSort = DefaultBoolean.False;
            column.Width = 70;
        });

        settings.Columns.Add(column =>
        {
            column.Caption = "采购申请单号";
            column.FieldName = "FItemPurchaseApplyID";
            column.Width = 80;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        });
        settings.Columns.Add(column =>
        {
            column.Caption = "申请部门";
            column.FieldName = "DeptName";
            column.Width = 80;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        });
        
        settings.Columns.Add(column =>
        {
            column.Caption = "申请人";
            column.FieldName = "FEmpName";
            column.Width = 80;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        });
        settings.Columns.Add(column =>
        {
            column.Caption = "申请原因";
            column.FieldName = "FApplyReason";
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Left;
        });
        settings.Columns.Add(column =>
        {
            column.Caption = "填报日期";
            column.SetDataItemTemplateContent(c =>
            {

                DateTime dt = DateTime.Parse(DataBinder.Eval(c.DataItem, "FApplyDate").ToString());
                ViewContext.Writer.Write(dt.ToString("yyyy-MM-dd"));
            });
            column.Width = 100;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        });

        settings.Columns.Add(column => 
        {
            column.Caption = "明细数量";
            column.FieldName = "Cou";
            column.Width = 70;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;     
        });

        settings.Columns.Add(column =>
        {
            column.Caption = "是否通过审核";
            column.SetDataItemTemplateContent(c =>
            {
                if (DataBinder.Eval(c.DataItem, "FStatus").ToString() == "N") {
                    ViewContext.Writer.Write("新单");
                }
                else if (DataBinder.Eval(c.DataItem, "FStatus").ToString() == "A") {
                    ViewContext.Writer.Write("通过");
                }
                else if (DataBinder.Eval(c.DataItem, "FStatus").ToString() == "R") {
                    ViewContext.Writer.Write("未通过");
                }
                
              
            });
            column.Width = 80;
            column.CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
        });
        
        settings.SettingsBehavior.AllowSort = false;
        settings.SettingsBehavior.AllowDragDrop = false;
        settings.SettingsBehavior.AllowSelectByRowClick = false;
        settings.SettingsLoadingPanel.Text = "数据读取中...";
        settings.SettingsBehavior.AllowClientEventsOnLoad = false;
        settings.SettingsBehavior.AllowFocusedRow = true;


        settings.ClientSideEvents.BeginCallback = "function(s,e){OnBeginCallback(s,e)}";

        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        settings.CommandColumn.Width = System.Web.UI.WebControls.Unit.Pixel(5);

        settings.SettingsPager.Position = System.Web.UI.WebControls.PagerPosition.Bottom;
        settings.SettingsPager.FirstPageButton.Visible = true;
        settings.SettingsPager.LastPageButton.Visible = true;
        settings.SettingsPager.PageSize = ElingOA6_Admin_DSJCJ.Common.GlobalConstant.CONSTRING_PAGESIZE;
        settings.SettingsPager.AlwaysShowPager = true;

        settings.CommandColumn.SetHeaderTemplateContent(c =>
        {
            Html.DevExpress().CheckBox(settingsCheckBox =>
            {
                settingsCheckBox.Name = "cbSelectAll";
                settingsCheckBox.Properties.ClientSideEvents.CheckedChanged = string.Format("function(s, e) {{ if(s.GetChecked()) {0}.SelectAllRowsOnPage(); else {0}.UnselectAllRowsOnPage(); }}", settings.Name);

                if (c.Grid.VisibleRowCount == 0)
                {
                    settingsCheckBox.Enabled = false;

                }
                else
                {
                    settingsCheckBox.Checked = c.Grid.VisibleRowCount == c.Grid.Selection.Count;
                }


            }).Render();
        });


        settings.PageIndexChanged = (sender, e) =>
        {
            ASPxGridView grid = (ASPxGridView)sender;
            grid.Selection.UnselectAll();
        };
        settings.DataBinding = (sender, e) =>
        {
            ASPxGridView grid = (ASPxGridView)sender;
            for (int i = 0; i < grid.AllColumns.Count; i++)
            {
                if (grid.AllColumns[i].CellStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                {
                    grid.AllColumns[i].CellStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                }
                if (grid.AllColumns[i].HeaderStyle.HorizontalAlign == System.Web.UI.WebControls.HorizontalAlign.NotSet)
                {
                    grid.AllColumns[i].HeaderStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
                }
            }
        };
    }).Bind(Model).GetHtml()